import json
import time

import requests

from Spider.fund import get_buy_sell_1, get_fund_assessment_dongfangcaifu, get_fund_assessment_jisilu


def _test_get_fund_assessment_tiantianjijin():
    while True:
        time.sleep(2)
        data = get_fund_assessment_dongfangcaifu(163417)
        print(data)


def _test_get_buy_sell_1():
    while True:
        time.sleep(2)
        data = get_buy_sell_1(163417)
        print(data)


def _test_get_fund_assessment_jisilu():
    while True:
        time.sleep(2)
        data = get_fund_assessment_jisilu()
        print(data)
        print(data.__len__())


def _test_get_close_before_2():
    fund_code = 160105
    url = "https://web.ifzq.gtimg.cn/appstock/app/minute/query?code=sz{}".format(fund_code)
    res = requests.get(url)
    data = json.loads(res.text)
    try:
        close_2m = data["data"]["sz{}".format(fund_code)]["data"]["data"][-2].split(" ")[1]
    except Exception as e:
        print()
    print()
    return {
        "increase_2m": res
    }

    pass


if __name__ == '__main__':
    # _test_get_fund_assessment_tiantianjijin()
    # _test_get_buy_sell_1()
    # _test_get_fund_assessment_jisilu()
    _test_get_close_before_2()
